<?php
//****************************************************************
//Author: Alex Zdvorak
//Date: 12/6/2009
//contact: zdvor001@csusm.edu
//
// Purpose: The purpose of employee.php is to display information
//			about a specified employee. The edit buttons will be
//			output if the current user is an employee giving them
//			sufficient privlages to edit attributes.
//
// Expected: This page recieves the post variable 'empID' to
//			determine what employee to display information about.
//
// Output: This page displays information about the employee
//			including Name, Id, Employment Date, Title, Specialty
//			department, Team, Contact Information, Extension,
//			Location, and ManagerID
//****************************************************************
session_start();
require_once 'php_includes.php';

//Make sure logged in
checkLogin();


	if(isset($_SESSION['empID']))
	{
		$_POST['empID'] = $_SESSION['empID'];//set the posts so they can be used	
		unset($_SESSION['empID']);//unset the session vars
	}

if(!$_POST['empID'])
{
	$empID=$_SESSION['tmsUserID'];
	
}
else
{
	$empID = $_POST['empID'];
}



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  
  <head>
    <title>Payroll and Timesheet Management Website</title>
    <link rel="stylesheet" type="text/css" href="styles.css"/>
	<link rel="stylesheet" type="text/css" href="employee.css"/>
  </head>
  <body>
        <?php writeHeader(); ?>
        <p>
        <span class="pageheader">Employee Information</span>
        </p>
        
   
    <?php
                //Establishes connection to the database
                sqlConnect();
                $con=sqlConnect();
                mysql_select_db("titans", $con);
            
								
                //Gather employee information
                /***********************\
                *                       *
                *       First Name      *
                *       Last Name       *
                *       Portrait        *
                *       Start Date      *
                *       title           *
                *       Specialty       *
                *       Department      *
                *       Team            *
                *       Email           *
                *       Extension       *
                *       Location        *
                *       Manager         *
                *                       *
                \***********************/       
                 
                $SQLstring="SELECT EmployeeFName, EmployeeLName, EmployeePortrait, EmployeeStartDate, EmployeeTitle, EmployeeSpecialty, EmployeeDepart, EmployeeTeam, EmployeeContact, EmployeeExtension, EmployeeLoc, ManagerID FROM Employee WHERE EmployeeID = '" . $empID . "'";
                $sqlresult=sqlQuery($SQLstring);
                
                $fname = mysql_result($sqlresult, 0, 0);
                $lname = mysql_result($sqlresult, 0, 1);
                $portrait = mysql_result($sqlresult, 0, 2);
                $startDate = mysql_result($sqlresult, 0, 3);
                $title = mysql_result($sqlresult, 0, 4);
                $specialty = mysql_result($sqlresult, 0, 5);
                $department = mysql_result($sqlresult, 0, 6);
                $team = mysql_result($sqlresult, 0, 7);
                $email = mysql_result($sqlresult, 0, 8);
                $extension = mysql_result($sqlresult, 0, 9);
                $location = mysql_result($sqlresult, 0, 10);
                $manager = mysql_result($sqlresult, 0, 11);

                echo "<div class=\"user_logged\">";
                echo "</div>";
            
                
                //Start sidebar
                //Display Name and ID
                echo "<div class=\"sidebar\">";
                echo "<!--basic employee info -->";
                echo "<div class=\"center\">";
                echo "<span class=\"employ_name\">";
                echo $fname . " " . $lname;
                echo "</span>";
                echo "<span class=\"employ_id\">";
                echo " (" . $empID. ")";
                echo "</span>";
                echo "<br/>";
                echo "<span class=\"edit\">";
                
                //Display edit button if the user is an employee
                if($_SESSION['tmsUserType'])
                {
					echo "<form action=\"editemployee.php\" method=\"post\" target=\"edit_employee_info\" onSubmit=\"window.open('', 'edit_employee_info', 'width=450,height=300,status=yes,resizable=yes,scrollbars=yes')\">";
					echo "<div class=\"center\">";				
					echo "<input type=\"hidden\" name=\"empID\"value=\"" . $empID . "\" />";
					echo "<input type=\"submit\" value=\"EDIT EMPLOYEE INFORMATION\" class=\"button\" />";
					echo "</div></form>"; 
                }
                
                //Display Portrait
                echo "</span>";
                echo "</div>";
                echo "<br/>";
                echo "<br/>";
                echo "<div class=\"center\">";
				if(trim($portrait) == "")
				{
					echo "<img src=\"portrait.png\" alt=\"" . $fname . " " . $lname . "\"/>";
				}
				else
				{
					echo "<img src=\"".$portrait."\" alt=\"" . $fname . " " . $lname . "\"/>";
				}
                echo "<br/>";
                echo "<span class=\"edit\">";
                                
                //Display Start Date			
                echo "</span>";
                echo "</div>";
                echo "<br/>";
                echo "<div class=\"center\">";
                echo "<span class=\"employ_since\">";
                echo "Employee since: " . $startDate;
                echo "</span>";
                echo "</div>";
                echo "</div>";
                //End sidebar
                
                //Display Title
                echo "<div class=\"info\">";
                echo "<!-- info -->";
                echo "<div>";
                echo "<span class=\"employ\">";
                echo "Title:";
                echo "</span>";
                echo "<span class=\"edit\">";
                echo "<span class=\"employ_info\">";
                echo " $title";
                
                //Display Specialty			
                echo "</span>";
                echo "</div>";
                echo "<br/>";
                echo "<div>";
                echo "<span class=\"employ\">";
                echo "Specialty:";
                echo "</span>";
                echo "<span class=\"edit\">";           
                echo "</span>";
                echo "<span class=\"employ_info\">";
                echo " $specialty";
                
                //Display Department			
                echo "</span>";
                echo "</div>";
                echo "<br/>";
                echo "<div>";
                echo "<span class=\"employ\">";
                echo "Department:";
                echo "</span>";
                echo "<span class=\"edit\">";
                echo "</span>";
                echo "<span class=\"employ_info\">";
                echo " $department";
                
                //Display Team           
                echo "</span>";
                echo "</div>";
                echo "<br/>";
                echo "<div>";
                echo "<span class=\"employ\">";
                echo "Team:";
                echo "</span>";
                echo "<span class=\"edit\">";  
                echo "</span>";
                echo "<span class=\"employ_info\">";
                echo " $team";
                
                //Display Contact Information         
                echo "</div>";
                echo "<br/>";
                echo "<div>";
                echo "<span class=\"employ\">";
                echo "Contact Information:";
                echo "</span>";
                echo "<span class=\"edit\">";
                echo "</span>";
                echo "<span class=\"employ_info\">";
                echo " $email";
                
                //Display Extension                
                echo "</span>";
                echo "</div>";
                echo "<br/>";
                echo "<div>";
                echo "<span class=\"employ\">";
                echo "Extension:";
                echo "</span>";
                echo "<span class=\"edit\">";
                echo "</span>";
                echo "<span class=\"employ_info\">";
                echo " $extension";
                
                //Display Location                
                echo "</span>";
                echo "</div>";
                echo "<br/>";
                echo "<div>";
                echo "<span class=\"employ\">";
                echo "Location:";
                echo "</span>";
                echo "<span class=\"edit\">";
                echo "</span>";
                echo "<span class=\"employ_info\">";
                echo " $location";
                
                //Display manager            
                echo "</span>";
                echo "</div>";
                echo "<br/>";
                echo "<div>";
                echo "<span class=\"employ\">";
                echo "Manager ID:";
                echo "</span>";
                echo "<span class=\"edit\">";
                echo "</span>";
                echo "<span class=\"employ_info\">";
                echo " $manager";
                          
                echo "</span>";
                echo "</div>";
                echo "</div>";
                //echo "</div>";

            sqlExit();
        ?>

  </body>
</html>